/*
 * uart_io.h
 *
 * Created: 8/22/2013 3:55:39 PM
 *  Author: Ken Arok
 *
 *
 * \brief Input Output Drivers for UART.
 *
 * Copyright (c) 2013 PT Hanindo Automation Solutions. All rights reserved.
 *
 */


#ifndef UART_IO_H_
#define UART_IO_H_

#include "config_peripherals.h"

#if UART_PERIPHERAL_ACTIVE

#include "io.h"


/** \brief UART Initialization.
 */
void uart_io_init(void);

/** \brief UART I/O Control.
 *
 * @param io_desc		Pointer to I/O COM port description.
 * @param reqCode		Request Code.
 * @param pValue		Pointer to the value.
 * @return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE uart_io_ctrl(io_descriptor_t io_desc, io_request_code_t reqCode, void *pValue);

/** \brief UART Open Peripheral.
 *
 * @param path_name		Path name of COM port.
 * @param flag			Flag of opening.
 * @return	Pointer of I/O COM port description.
 *
 */
io_descriptor_t uart_io_open(IO_path path_name, const uint8_t flag);

/** \brief UART Close Peripheral.
 *
 * @param io_desc		Pointer to I/O COM port description.
 * @param flag			Flag of closing.
 * @return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE uart_io_close(io_descriptor_t io_desc, const uint8_t flag);

/** \brief UART Write Data to Peripheral.
 *
 * @param io_desc		Pointer to I/O COM port description.
 * @param pBuff			Pointer to the buffer of data to write.
 * @param size			Size of data to write.
 * @param flag			Flag of writing operation.
 * @return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE uart_io_write(io_descriptor_t io_desc, const void *pBuf, uint32_t size, io_rw_flag_t flag);

/** \brief UART Read Data from Peripheral.
 *
 * @param io_desc		Pointer to I/O COM port description..
 * @param pBuff			Pointer to the buffer where data will be copied.
 * @param size			Size of data to read.
 * @param flag			Flag of writing operation.
 * @return actual number of count of received data.
 *
 */
portBASE_TYPE uart_io_read(io_descriptor_t io_desc, void *pBuf, uint32_t size, io_rw_flag_t flag);

#else /* UART_PERIPHERAL_ACTIVE */

#define uart_io_init()
#define uart_io_ctrl(a, b, c)			pdFAIL
#define uart_io_open(a, b)				NULL
#define uart_io_close(a)				pdFAIL
#define uart_io_write(a, b, c, d)		pdFAIL
#define uart_io_read(a, b, c, d)		pdFAIL


#endif /* UART_PERIPHERAL_ACTIVE */


#endif /* UART_IO_H_ */
